import Vue from 'vue'
import vueRouter from 'vue-router'

import Main from '../pages/main.vue'
import Login from '../pages/login.vue'

const files = require.context('../pages', true, /[a-zA-Z]\.vue$/);

// console.log(files.keys())

let routes = files.keys().map(item => {
  let path = item.slice(1, -4)
  let name = item.slice(1, -4)
  let componentName = files(item).default.componentTitle

  return {
    path: path,
    name: name,
    component: files(item).default,
    mate: {
      title: componentName
    }
  }
})

Vue.use(vueRouter)

// console.log(routes)

const router = new vueRouter({
  routes: [
    {
      path: '/',
      redirect: '/login',
      component: Login,
    },
    {
      path: '/main',
      name: '/main',
      component: Main,
      children: routes
    },
    // {
    //   path: '/login',
    //   name: '/login',
    //   component: Login,
      
    // }
  ]
  // routes: routes
})

export default router